unit U_MasrafMerkeziListe;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, ADODB, StdCtrls, Buttons, ExtCtrls,
  cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxClasses, cxControls, cxGridCustomView, cxGrid, siComp;

type
  TfmMasrafMerkeziListe = class(TForm)
    cxgrid1: TcxGrid;
    cxgrid1DBTableView1: TcxGridDBTableView;
    cxgrid1DBTableView1ID: TcxGridDBColumn;
    cxgrid1DBTableView1MASKODU: TcxGridDBColumn;
    cxgrid1DBTableView1MASADI: TcxGridDBColumn;
    cxgrid1Level1: TcxGridLevel;
    pnl_alt: TPanel;
    BitBtn1: TBitBtn;
    DSListe: TDataSource;
    adoListe: TADOQuery;
    adoTemp: TADOQuery;
    procedure BitBtn1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
    procedure cxgrid1DBTableView1DblClick(Sender: TObject);
    procedure cxgrid1DBTableView1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormShow(Sender: TObject);
    procedure cxgrid1DBTableView1ColumnHeaderClick(
      Sender: TcxGridTableView; AColumn: TcxGridColumn);
  private
    { Private declarations }
  public
    Kodtext:string;
    ACKtext:string;
  end;

var
  fmMasrafMerkeziListe: TfmMasrafMerkeziListe;

implementation

uses ana1;

{$R *.dfm}

procedure TfmMasrafMerkeziListe.BitBtn1Click(Sender: TObject);
begin
  close;
end;

procedure TfmMasrafMerkeziListe.FormClose(Sender: TObject; var Action: TCloseAction);
begin
    Action:=CaFree;
    fmMasrafMerkeziListe:=nil;
end;

procedure TfmMasrafMerkeziListe.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   if key=27 then close;
end;

procedure TfmMasrafMerkeziListe.FormCreate(Sender: TObject);
begin
  adoListe.close;
  adoListe.SQL.Text:='select * from  CS_MUHASEBE_MASRAF_MERKEZI where AKTIF = 1 order by MASKODU';
  adoListe.Open;

  Kodtext:='';
  ACKtext:='';
end;

procedure TfmMasrafMerkeziListe.cxgrid1DBTableView1DblClick(
  Sender: TObject);
begin
 anaform.MODALRESULT[1]:=adoListe.Fieldbyname('ID').asinteger;
 anaform.MODALRESULT[2]:=adoListe.Fieldbyname('MASKODU').asstring;
 anaform.MODALRESULT[3]:=adoListe.Fieldbyname('MASADI').asstring;
 ModalResult:=mrOk;
end;

procedure TfmMasrafMerkeziListe.cxgrid1DBTableView1KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
 if key=13 then begin

 anaform.MODALRESULT[1]:=adoListe.Fieldbyname('ID').asinteger;
 anaform.MODALRESULT[2]:=adoListe.Fieldbyname('MASKODU').asstring;
 anaform.MODALRESULT[3]:=adoListe.Fieldbyname('MASADI').asstring;
 ModalResult:=mrOk;
 //close;

   end;
end;

procedure TfmMasrafMerkeziListe.FormShow(Sender: TObject);
begin
if Kodtext <> '' then begin
  adotemp.close;
  adotemp.sql.text:='select * from CS_MUHASEBE_MASRAF_MERKEZI where AKTIF=1 and MASKODU like :DD order by MASKODU';
  adotemp.Parameters.ParamByName('DD').Value:= KodText + '%' ;
  adoTemp.Open;
  if adotemp.RecordCount >0 then
     adoListe.Locate('MASKODU', adotemp.fieldbyname('MASKODU').Value ,[] );

  end;


  if ACKtext <> '' then begin
  adotemp.close;
  adotemp.sql.text:='select * from CS_MUHASEBE_MASRAF_MERKEZI where AKTIF=1 and MASADI like :DD order by MASADI';
  adotemp.Parameters.ParamByName('DD').Value:= AckText + '%'  ;
  adoTemp.Open;
  if adotemp.RecordCount >0 then
     adoListe.Locate('MASADI', adotemp.fieldbyname('MASADI').Value ,[] );

  end;
end;

procedure TfmMasrafMerkeziListe.cxgrid1DBTableView1ColumnHeaderClick(
  Sender: TcxGridTableView; AColumn: TcxGridColumn);
begin
If AColumn.SortOrder = soAscending Then
  Begin
    adoListe.sort := copy(AColumn.Name, 20, length(AColumn.Name) - 19) + ' DESC'
  End
  Else
  Begin
    adoListe.sort := copy(AColumn.Name, 20, length(AColumn.Name) - 19) + ' ASC';
  End;

  cxgrid1DBTableView1.OptionsBehavior.IncSearchItem := AColumn;
end;

end.